﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class easystarter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string group = Request["group"];
        if (group != null && group != "")
        {
            TextBox1.Text = group;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool exeOK = false;
        MembershipCreateStatus status;
        MembershipUser us = Membership.GetUser(TextBox1.Text);
        if (us == null)
        {//新規グループ-->適当なパスワードでメンバシップ登録
            string pass = Membership.GeneratePassword(10, 2);
            Membership.CreateUser(TextBox1.Text, pass, "", "not required", "not required", true, out status);
            if (status == MembershipCreateStatus.Success)
            {
                exeOK = DataBaseAccessGroup.RegisterAnonymousGroup(TextBox1.Text);
            }
        }
        else
        {//すでにだれかが作っているグループ。アノニマスかどうかは不明。
            //アノニマス-->許可
            if (DataBaseAccessGroup.IsAnonymousGroup(TextBox1.Text))
            {
                exeOK = true;
            }
            else
            {
                //グループ管理されている-->不可
                exeOK = false;
            }
        }

        if (exeOK)
        {
            Response.Redirect(Launcher.LaunchEasyUrl(TextBox1.Text), true);
        }
        else
        {
            Label1.Visible = true;
        }
    }
}
